cssparser: Add error functions that take locations
authorBenjamin Otte <otte@redhat.com>
Wed, 10 Apr 2019 17:42:09 +0000 (19:42 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 12 Apr 2019 17:34:28 +0000 (19:34 +0200)
... and use them to report better error locations for the warning when
blocks aren't terminated properly.

gtk/css/gtkcssparser.c
gtk/css/gtkcssparserprivate.h

index b3347ee0674a56f2dfbbb6d01fa9237211ec76ec..e812df259b770c64f62524e7f6d37c9f4b8e8eba 100644 (file)
@@ -415,13 +415,21 @@ gtk_css_parser_end_block (GtkCssParser *self)
 
   if (gtk_css_token_is (&self->token, GTK_CSS_TOKEN_EOF))
     {
-      gtk_css_parser_warn_syntax (self, "Unterminated block at end of document");
+      gtk_css_parser_warn (self,
+                           GTK_CSS_PARSER_WARNING_SYNTAX,
+                           gtk_css_parser_get_block_location (self),
+                           gtk_css_parser_get_start_location (self),
+                           "Unterminated block at end of document");
       g_array_set_size (self->blocks, self->blocks->len - 1);
     }
   else if (gtk_css_token_is (&self->token, block->inherited_end_token))
     {
       g_assert (block->end_token == GTK_CSS_TOKEN_SEMICOLON);
-      gtk_css_parser_warn_syntax (self, "Expected ';' at end of block");
+      gtk_css_parser_warn (self,
+                           GTK_CSS_PARSER_WARNING_SYNTAX,
+                           gtk_css_parser_get_block_location (self),
+                           gtk_css_parser_get_start_location (self),
+                           "Expected ';' at end of block");
       g_array_set_size (self->blocks, self->blocks->len - 1);
     }
   else
@@ -498,6 +506,26 @@ gtk_css_parser_emit_error (GtkCssParser         *self,
     self->error_func (self, start, end, error, self->user_data);
 }
 
+void
+gtk_css_parser_error (GtkCssParser         *self,
+                      GtkCssParserError     code,
+                      const GtkCssLocation *start,
+                      const GtkCssLocation *end,
+                      const char           *format,
+                      ...)
+{
+  va_list args;
+  GError *error;
+
+  va_start (args, format);
+  error = g_error_new_valist (GTK_CSS_PARSER_ERROR,
+                              code,
+                              format, args);
+  gtk_css_parser_emit_error (self, start, end, error);
+  g_error_free (error);
+  va_end (args);
+}
+
 void
 gtk_css_parser_error_syntax (GtkCssParser *self,
                              const char   *format,
@@ -558,6 +586,26 @@ gtk_css_parser_error_import (GtkCssParser *self,
   va_end (args);
 }
 
+void
+gtk_css_parser_warn (GtkCssParser         *self,
+                     GtkCssParserWarning   code,
+                     const GtkCssLocation *start,
+                     const GtkCssLocation *end,
+                     const char           *format,
+                     ...)
+{
+  va_list args;
+  GError *error;
+
+  va_start (args, format);
+  error = g_error_new_valist (GTK_CSS_PARSER_WARNING,
+                              code,
+                              format, args);
+  gtk_css_parser_emit_error (self, start, end, error);
+  g_error_free (error);
+  va_end (args);
+}
+
 void
 gtk_css_parser_warn_syntax (GtkCssParser *self,
                             const char   *format,
index 2942bb86f186a13e3b84b315e3dd5fe71ec20ada..31b44cbce6948c1724c0eb69562d4b3c2d6a3d5e 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef __GTK_CSS_PARSER_H__
 #define __GTK_CSS_PARSER_H__
 
+#include "gtkcssenums.h"
 #include "gtkcsstokenizerprivate.h"
 
 #include <gio/gio.h>
@@ -87,6 +88,12 @@ void                    gtk_css_parser_emit_error               (GtkCssParser
                                                                  const GtkCssLocation           *start,
                                                                  const GtkCssLocation           *end,
                                                                  const GError                   *error);
+void                    gtk_css_parser_error                    (GtkCssParser                   *self,
+                                                                 GtkCssParserError               code,
+                                                                 const GtkCssLocation           *start,
+                                                                 const GtkCssLocation           *end,
+                                                                 const char                     *format,
+                                                                 ...) G_GNUC_PRINTF(5, 6);
 void                    gtk_css_parser_error_syntax             (GtkCssParser                   *self,
                                                                  const char                     *format,
                                                                  ...) G_GNUC_PRINTF(2, 3);
@@ -96,6 +103,12 @@ void                    gtk_css_parser_error_value              (GtkCssParser
 void                    gtk_css_parser_error_import             (GtkCssParser                   *self,
                                                                  const char                     *format,
                                                                  ...) G_GNUC_PRINTF(2, 3);
+void                    gtk_css_parser_warn                     (GtkCssParser                   *self,
+                                                                 GtkCssParserWarning             code,
+                                                                 const GtkCssLocation           *start,
+                                                                 const GtkCssLocation           *end,
+                                                                 const char                     *format,
+                                                                 ...) G_GNUC_PRINTF(5, 6);
 void                    gtk_css_parser_warn_syntax              (GtkCssParser                   *self,
                                                                  const char                     *format,
                                                                  ...) G_GNUC_PRINTF(2, 3);